package com.itheima.controller;

import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import com.itheima.pojo.Category;
import com.itheima.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;


/**
 * @author Adong
 * 商品类别
 */
@RestController
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分页查询数据
     * @param curPage
     * @param size
     * @return
     */
    @RequestMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer curPage,@PathVariable("size") Integer size){
        return categoryService.findPage(curPage,size);
   }

    /**
     * 根据id查询
     * @param id
     * @return
     */
   @RequestMapping("/{id}")
   public Result findById(@PathVariable("id") Integer id){
        return categoryService.findById(id);
   }

    /**
     * 添加
     * @param category
     * @return
     */
   @PostMapping
   public Result add(@RequestBody Category category){
       System.out.println(category);
       return categoryService.add(category);
   }

    /**
     * 根据id修改
     * @param category
     * @return
     */
   @PutMapping("/{id}")
   public Result updatePro(@RequestBody Category category){
      return categoryService.updatePro(category);

   }

   @DeleteMapping("/{id}")
   public Result deleteById(@PathVariable("id") Integer id){
       return categoryService.deleteByid(id);
   }
}
